package com.wjc.train.member.controller;

import com.wjc.train.common.resp.CommonResp;
import com.wjc.train.member.req.MemberLoginReq;
import com.wjc.train.member.req.MemberRegisterReq;
import com.wjc.train.member.req.MemberSendCodeReq;
import com.wjc.train.member.resp.MemberLoginResp;
import com.wjc.train.member.service.IMemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Guessed
 */
@RestController
@Validated
@RequestMapping("/member")
public class MemberController {

    @Resource
    private IMemberService memberService;


    @PostMapping("/register")
    public CommonResp<Boolean> register(@RequestBody @Valid List<MemberRegisterReq> memberList) {
        return new CommonResp<>(memberService.register(memberList));
    }

    @PostMapping("/send-code")
    public CommonResp<Boolean> sendCode(@RequestBody @Valid MemberSendCodeReq memberSendCodeReq) {
        memberService.sendCode(memberSendCodeReq);
        return CommonResp.success();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@RequestBody @Valid MemberLoginReq memberLoginReq) {
        MemberLoginResp memberLoginResp = memberService.login(memberLoginReq);
        return CommonResp.success(memberLoginResp);
    }

}
